package id.co.rho.scoring.cid.client.security.impl;

import id.co.rho.scoring.cid.client.security.Credential;
import id.co.rho.scoring.cid.client.security.CredentialConfigurer;
import id.co.rho.scoring.cid.shared.model.FunctionGroupModel;

import java.io.Serializable;
import java.util.HashSet;
import java.util.List;

/**
 * Credential asli, cuma untuk dipake selama development.
 * User: bungrudi
 * Date: 8/9/11
 * Time: 1:15 PM
 */
public class RealCredential implements Credential, CredentialConfigurer, Serializable{
	Long id;
    String userId;
    String username;
    String password;
    String userStatus;
	List<FunctionGroupModel> listRole;
    private HashSet<String> functionTokens;

    @Override
    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    @Override
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

	public List<FunctionGroupModel> getListRole() {
		return listRole;
	}

	public void setListRole(List<FunctionGroupModel> listRole) {
		this.listRole = listRole;
        functionTokens = null;
        if(this.listRole != null) {
            List<String> functionCodeList = FunctionGroupModel.getListAllFunctionCode(listRole);
            functionTokens = new HashSet<String>(functionCodeList);
        }
	}

    @Override
    public boolean isHaveFunction(String functionToken) {
        if(functionTokens != null) {
            return functionTokens.contains(functionToken);
        }
        return false;
    }

    @Override
	public Long getId() {
		return id;
	}

	@Override
	public void setId(Long id) {
		this.id = id;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Override
	public String getUserStatus() {
		// TODO Auto-generated method stub
		return this.userStatus;
	}

	public void setUserStatus(String userStatus) {
		this.userStatus = userStatus;
	}
	
	
	
}
